package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Admission;
import com.ruoyi.system.service.IAdmissionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住院申请Controller
 * 
 * @author 墨白
 * @date 2024-08-10
 */
@RestController
@RequestMapping("/system/admission")
public class AdmissionController extends BaseController
{
    @Autowired
    private IAdmissionService admissionService;

    /**
     * 查询住院申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:admission:list')")
    @GetMapping("/list")
    public TableDataInfo list(Admission admission)
    {
        startPage();
        List<Admission> list = admissionService.selectAdmissionList(admission);
        return getDataTable(list);
    }

    /**
     * 导出住院申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:admission:export')")
    @Log(title = "住院申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Admission admission)
    {
        List<Admission> list = admissionService.selectAdmissionList(admission);
        ExcelUtil<Admission> util = new ExcelUtil<Admission>(Admission.class);
        util.exportExcel(response, list, "住院申请数据");
    }

    /**
     * 获取住院申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:admission:query')")
    @GetMapping(value = "/{admissionId}")
    public AjaxResult getInfo(@PathVariable("admissionId") Long admissionId)
    {
        return success(admissionService.selectAdmissionByAdmissionId(admissionId));
    }

    /**
     * 新增住院申请
     */
    @PreAuthorize("@ss.hasPermi('system:admission:add')")
    @Log(title = "住院申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Admission admission)
    {
        return toAjax(admissionService.insertAdmission(admission));
    }

    /**
     * 修改住院申请
     */
    @PreAuthorize("@ss.hasPermi('system:admission:edit')")
    @Log(title = "住院申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Admission admission)
    {
        return toAjax(admissionService.updateAdmission(admission));
    }

    /**
     * 删除住院申请
     */
    @PreAuthorize("@ss.hasPermi('system:admission:remove')")
    @Log(title = "住院申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{admissionIds}")
    public AjaxResult remove(@PathVariable Long[] admissionIds)
    {
        return toAjax(admissionService.deleteAdmissionByAdmissionIds(admissionIds));
    }
}
